package com.sharding.demo.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sharding.demo.entity.CommonDict;
import com.sharding.demo.service.CommonDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController()
@RequestMapping("/udict")
public class CommonDictController {
 
    @Autowired
    private CommonDictService CommonDictService;
 
    @GetMapping("/select")
    public List<CommonDict> select() {

        return CommonDictService.getBaseMapper().selectList(null);
    }

    @GetMapping("/selectPage")
    public IPage<CommonDict> selectUserPage(Integer pageSize, Integer pageNumber, CommonDict state) {
        // 不进行 count sql 优化，解决 MP 无法自动优化 SQL 问题，这时候你需要自己查询 count 部分
        // page.setOptimizeCountSql(false);
        // 当 total 为小于 0 或者设置 setSearchCount(false) 分页插件不会进行 count 查询
        // 要点!! 分页返回的对象与传入的对象是同一个
        Page<CommonDict> page = new Page<>(pageNumber, pageSize);
        return CommonDictService.selectPageVo(page, state);
    }

    @GetMapping("/insert")
    public Boolean insert(CommonDict CommonDict) {
        return CommonDictService.save(CommonDict);
    }

}